package demo1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Game {
    private static final String[] suits = {"♥", "♣", "♦", "♠"};

    //生成牌
    public List<Poker> buyPoker() {
        List<Poker> pokerList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                Poker poker = new Poker(suits[i], j);
                pokerList.add(poker);
            }
        }
        return pokerList;
    }

    //洗牌
    public void shuffle1(List<Poker> pokerList) {
        for (int i = 0; i < pokerList.size(); i++) {
            Random random = new Random();
            int index = random.nextInt(pokerList.size());

            swap(pokerList, i, index);
        }
    }

    public void shuffle2(List<Poker> pokerList) {
        for (int i = pokerList.size() - 1; i > 0; i--) {
            Random random = new Random();
            int index = random.nextInt(i);

            swap(pokerList, i, index);
        }
    }

    private void swap (List<Poker> pokerList, int i, int j) {
        Poker tmp = pokerList.get(i);
        pokerList.set(i, pokerList.get(j));
        pokerList.set(j, tmp);
    }

    //揭牌
    public List<List<Poker>> game(List<Poker> pokerList) {
        List<List<Poker>> lists = new ArrayList<>();
        List<Poker> list1 = new ArrayList<>();
        List<Poker> list2 = new ArrayList<>();
        List<Poker> list3 = new ArrayList<>();
        lists.add(list1);
        lists.add(list2);
        lists.add(list3);

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < lists.size(); j++) {
                (lists.get(j)).add(pokerList.remove(0));
            }
        }

        return lists;
    }
}
